<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ include file="../include/header.jsp" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Admin List Page</title>
<script type="text/javascript">
$(document).ready(function(){
	$("#state").val(0);
	$("#class_date").val(new Date().toDateInputValue());		
	$("#offset").val(0);
	class_list();	
	menu_button(0);
	auto_class_done();
});

function select_state(state){
	$("#state").val(state);	
	class_list();	
	menu_button(state);
}

function menu_button(state){
	var docu = "";
	if(state == 0){		
		docu =	"<input type='button' value='승인기능버튼 예시'   />";		
	}else if(state ==1){
		docu =	"<input type='button' value='폐강대상 정리' onclick='classCloseAll()' style='color:red; font-weight:bold; height:30px; '  />수강인원 5명 이하 && 강좌일자 7일 이내";		
	}else if(state ==2){
		docu =	"<input type='button' value='강의완료버튼 예시'   />";		
	}else if(state ==3){
		docu =	"<input type='button' value='폐강기능버튼 예시'   />";		
	}
	$('#menu_button').html(docu);	
}

function class_list(){
	var state = $("#state").val();
	var offset = $("#offset").val();	
	var op_date = $("#class_date").val();
	var op_direction = $("#op_direction").val();
	var op_order = $("#op_order").val();	
	var param = "offset="+offset
	+"&op_date="+op_date
	+"&op_direction="+op_direction
	+"&op_order="+op_order
	+"&state="+state;	
	$.ajax({
		type:"post",
		url:"${path}/admin/admin_class_list.do",
		data:param,
		success:function(msg){
			$("#class_list").html(msg);				
		}		
	});	
}

function classCloseAll(){
	if(confirm("폐강대상 강의를 모두 정리하시겠습니까?")){
		$.ajax({
			type:"post",
			url:"${path}/admin/admin_class_autoClose.do",			
			success:function(){				
				class_list();
				alert("자동 폐강 되었습니다");
			}		
		});		
	}
}

function class_close(idx){
	if(confirm(idx+"번 강의를 폐강 하시겠습니까?")){
		var param = "idx="+idx
		$.ajax({
			type:"post",
			url:"${path}/admin/admin_class_Close.do",
			data:param,
			success:function(){				
				class_list();				
			}		
		});		
	}	
}

function auto_class_done(){
	$.ajax({
		type:"post",
		url:"${path}/admin/admin_auto_class_done.do",			
		success:function(){	
			alert("강의 완료된 리스트가 정리 되었습니다");
		}		
	});	
}

Date.prototype.toDateInputValue = (function() {
    var local = new Date(this);
    local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
    return local.toJSON().slice(0,10);
});
</script>
</head>
<body>
	<table  border="1" style=" width: 100%;">
		<tr>
			<th style=" height: 90px;">
				<div style="height:90%; width:90%; margin: 0 auto;">
					<table border="1" style="border:solid black;  height: 100%; width: 100%; ">
						<tr>
							<th>분류</th>
							<th>
								<input type="button" value="승인대기"  onclick="select_state('0')" style="width:100px; height: 30px; font-weight: bold; ">
								<input type="button" value="개설완료"  onclick="select_state('1')" style="width:100px; height: 30px; font-weight: bold; ">
								<input type="button" value="강의종료"  onclick="select_state('2')" style="width:100px; height: 30px; font-weight: bold; ">
								<input type="button" value="폐강"  onclick="select_state('3')" style="width:100px; height: 30px; font-weight: bold; ">								
							</th>
							<th>
								<input type="hidden" id="state" name="state" />
								<input type="hidden" id="offset" name="offset" />
								<input type="date" id="class_date" name="class_date" onchange="class_list()">								
								<select id="op_direction"  name="op_direction" onchange="class_list()">
									<option value="gt">이후</option>
									<option value="lt">이전</option>
								</select>
								
								<select id="op_order"  name="op_order" onchange="class_list()">
									<option value="asc" >오름차순</option>
									<option value="desc">내림차순</option>
								</select>
							</th>
						</tr>
						 
						<tr>
							<th>
								caution!!
							</th>
							<th colspan="2">
								<div id="menu_button">
								</div>
							</th>							
						</tr>
						 
					</table>
				</div>			
			</th>
		</tr>
		<tr>
			<th style="height:550px; ">
				<div id="class_list" style="height:95%; width:90%; margin-left: 50px;margin-top:10px; margin-bottom: 10px;  ">
				
				</div>
			</th>
		</tr>
	</table>
	
	
	

</body>
</html>